package com.my.study.designPatterns.statePattern;

public class BigWinnerState extends State {

    private GumballMachine gumballMachine;

    public BigWinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    @Override
    public void insertQuarter() {
        System.out.println("Big winner is comming, please wait");
    }

    @Override
    public void rejectQuarter() {

        System.out.println("You had turned crank, can not return money");
    }

    @Override
    public void turnCrank() {
        System.out.println("You had turned crank, can not turn crank twice");
    }

    @Override
    public void dispense() {

        System.out.println("You had win the biggest award");
        gumballMachine.releaseBall();
        if(gumballMachine.getCount() == 0){
            gumballMachine.setState(gumballMachine.getSoldOutState());
        }else {
            gumballMachine.releaseBall();
            if(gumballMachine.getCount() > 0){
                gumballMachine.setState(gumballMachine.getHasQuarterState());
            }else{
                gumballMachine.setState(gumballMachine.getSoldOutState());
                System.out.println("Oops, out of gumballs");
            }
        }

    }
}
